<?php

/**
 * This is the model class for table "{{city_app}}".
 *
 * The followings are the available columns in table '{{city_app}}':
 * @property string $id
 * @property integer $city_id
 * @property string $en_name
 * @property integer $status
 * @property string $user_token
 * @property string $wx_guid
 * @property string $wx_name
 * @property string $wx_id
 * @property string $wx_token
 * @property string $wx_api_url
 * @property string $wx_app_id
 * @property string $wx_app_secret
 * @property string $company_phone
 * @property string $type
 */
class CityApp extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{city_app}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('city_id, en_name, user_token, wx_guid, wx_name, wx_id, wx_token, wx_api_url, wx_app_id, wx_app_secret, company_phone', 'required'),
			array('city_id, status', 'numerical', 'integerOnly'=>true),
			array('en_name', 'length', 'max'=>50),
			array('user_token', 'length', 'max'=>10),
			array('wx_guid, wx_name, wx_id, wx_app_id, wx_app_secret', 'length', 'max'=>60),
			array('wx_token, company_phone', 'length', 'max'=>20),
			array('wx_api_url', 'length', 'max'=>255),
			array('type', 'length', 'max'=>6),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id,is_type, city_id, en_name, status, user_token, wx_guid, wx_name, wx_id, wx_token, wx_api_url, wx_app_id, wx_app_secret, company_phone, type', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'city_id' => 'City',
			'en_name' => 'En Name',
			'status' => 'Status',
			'user_token' => 'User Token',
			'wx_guid' => 'Wx Guid',
			'wx_name' => 'Wx Name',
			'wx_id' => 'Wx',
			'wx_token' => 'Wx Token',
			'wx_api_url' => 'Wx Api Url',
			'wx_app_id' => 'Wx App',
			'wx_app_secret' => 'Wx App Secret',
			'company_phone' => 'Company Phone',
			'type' => 'Type',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('city_id',$this->city_id);
		$criteria->compare('en_name',$this->en_name,true);
		$criteria->compare('status',$this->status);
		$criteria->compare('user_token',$this->user_token,true);
		$criteria->compare('wx_guid',$this->wx_guid,true);
		$criteria->compare('wx_name',$this->wx_name,true);
		$criteria->compare('wx_id',$this->wx_id,true);
		$criteria->compare('wx_token',$this->wx_token,true);
		$criteria->compare('wx_api_url',$this->wx_api_url,true);
		$criteria->compare('wx_app_id',$this->wx_app_id,true);
		$criteria->compare('wx_app_secret',$this->wx_app_secret,true);
		$criteria->compare('company_phone',$this->company_phone,true);
		$criteria->compare('type',$this->type,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return CityApp the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
